home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Nt / Demo / dl.nt / template / yourmodule.cpp < prev   
Encoding:
C/C++ Source or Header  |  1995-12-17  |  1.4 KB  |  53 lines  |  [TEXT/R*ch]

  1. /*************************************************************************
  2.  
  3.     This is a generic "template" file for building DLL extension
  4.     files for Python on NT.
  5.  
  6.     Replace all occurences of "your" with something appropriate!
  7.     Do this in the makefile too!
  8.  
  9.     This could be a C file, but the Python make will force the build
  10.     as C++.  This is due to a limitation in DLL's.  Apparently, when 
  11.     dynamically linking to _variables_ (which Python must) a C++ compiler
  12.     must be used, as the C compiler does not guarantee correct initialisation
  13.     of static data (or some such!  Anyway, it gives compile errors!)
  14.  
  15. *************************************************************************/
  16.  
  17. /* yourmodule.cpp -- module for something */
  18.  
  19. #include "windows.h"
  20.  
  21. // windows seems to define these macros too.
  22. #undef INCREF
  23. #undef DECREF
  24.  
  25. #include "allobjects.h"
  26. #include "modsupport.h"
  27.  
  28. static object *your_module_error;
  29.  
  30. static object *
  31. your_python_method(object * self, object * args)
  32. {
  33.     INCREF(None);
  34.     return None;
  35. }
  36.  
  37. /* List of functions exported by this module */
  38. static struct methodlist your_functions[] = {
  39.     {"your_python_method",        (method)your_python_method},
  40.     {NULL,            NULL}         /* Sentinel */
  41. };
  42.  
  43.  
  44. void
  45. inityour(void)
  46. {
  47.     object *dict, *module;
  48.     module = initmodule("your", your_functions);
  49.     dict = getmoduledict(module);
  50.     your_module_error = newstringobject("your error");
  51.     dictinsert(dict, "error", your_module_error);
  52. }
  53.